<style lang="less">
    @import '../../styles/common.less';
    @import '../tables/components/table.less';
</style>
<template>
    <div>
        <Card >
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="200">
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="USDI提现手续费" prop="serviceChargeRate">
                        <Input v-model="formValidate.serviceChargeRate"  placeholder="请输入USD提现手续费"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿石转账手续费" prop="serviceChargeRateKs">
                        <Input v-model="formValidate.serviceChargeRateKs" placeholder="请输入矿石转账手续费"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="USDI最低转账" prop="usdiatm">
                        <Input v-model="formValidate.usdiatm" placeholder="请输入最低转账"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="USDT最低转账" prop="usdtatm">
                        <Input v-model="formValidate.usdtatm" placeholder="请输入最高转账"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="最低转账" prop="lowest">
                        <Input v-model="formValidate.lowest" placeholder="请输入最低转账"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="最高转账" prop="highest">
                        <Input v-model="formValidate.highest" placeholder="请输入最高转账"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="矿石奖励上月(锁仓)转账开始时间" prop="returnOreTransfer">
                        <DatePicker type="datetime"   v-model="formValidate.returnOreTransfer"  format="yyyy-MM-dd HH:mm:ss" placeholder="请选择矿石奖励上月(锁仓)转账开始时间" style="width: 300px"></DatePicker>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="aitc释放周期(日)" prop="aitcRelease">
                        <Input v-model="formValidate.aitcRelease" placeholder="请输入aitc释放周期(日)"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="aitc释放比例" prop="aitcReleaseRatio">
                        <Input v-model="formValidate.aitcReleaseRatio" placeholder="请输入aitc释放比例"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="矿石本金释放周期(日)" prop="oreRelease">
                        <Input v-model="formValidate.oreRelease" placeholder="请输入矿石本金释放周期(日)"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿石本金释放比例" prop="oreReleaseRatio">
                        <Input v-model="formValidate.oreReleaseRatio" placeholder="请输入矿石本金释放比例"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <!--<Row :gutter="16">-->
                    <!--<Col span="12" >-->
                    <!--<FormItem label="是否开启矿机" prop="oreStatus">-->
                        <!--<Select  v-model="formValidate.oreStatus" placeholder="请选择是否开启矿机">-->
                            <!--<Option value="0">开启</Option>-->
                            <!--<Option value="1">关闭</Option>-->
                        <!--</Select>-->
                    <!--</FormItem>-->
                    <!--</Col>-->
                <!--</Row>-->
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="CTC交易手续费" prop="feeCtc">
                        <Input v-model="formValidate.feeCtc" placeholder="请输入CTC交易手续费"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="CTC最低挂单数量" prop="buyLowest">
                        <Input v-model="formValidate.buyLowest" placeholder="请输入CTC最低交易"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="CTC挂单最高数量" prop="highestNumber">
                        <Input v-model="formValidate.highestNumber" placeholder="请输入CTC挂单最高数量"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="CTC-USDI兑换矿石" prop="ctcExchangeRate">
                        <Input v-model="formValidate.ctcExchangeRate" placeholder="CTC兑换矿石汇率"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <!--<Row :gutter="16">-->
                    <!--<Col span="12" >-->
                    <!--<FormItem label="CTC最高交易" prop="buyHighest">-->
                        <!--<Input v-model="formValidate.buyHighest" placeholder="请输入CTC最高交易"></Input>-->
                    <!--</FormItem>-->
                    <!--</Col>-->
                <!--</Row>-->
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="BB交易手续费" prop="fee">
                        <Input v-model="formValidate.fee" placeholder="BBC交易手续费不得为空"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="BB最低交易" prop="aitBuyLowest">
                        <Input v-model="formValidate.aitBuyLowest" placeholder="请输入BB最低交易不得为空"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="BB最高交易" prop="aitcBuyHighest">
                        <Input v-model="formValidate.aitcBuyHighest" placeholder="请输入BB最高交易限制"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12" >
                    <FormItem label="BB交易开始时间" prop="creatime">
                        <DatePicker v-model="formValidate.creatime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="请选择BB开始时间" style="width: 300px"></DatePicker>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="BB交易结束时间" prop="endtime">
                        <DatePicker type="datetime"   v-model="formValidate.endtime"  format="yyyy-MM-dd HH:mm:ss" placeholder="请选择BB结束时间" style="width: 300px"></DatePicker>
                    </FormItem>
                    </Col>
                    <Col span="12" >
                    <FormItem label="USDI网体可提现比例" prop="canWithdrawRatio">
                        <Input v-model="formValidate.canWithdrawRatio" placeholder="请输入USDI网体可提现比例"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12" >
                    <FormItem label="网体提现开关" prop="onOffs">
                        <Select  v-model="formValidate.onOffs" placeholder="请选择是否开启网体提现">
                            <Option value="0">关闭</Option>
                            <Option value="1">开启</Option>
                        </Select>
                    </FormItem>
                    </Col>

                </Row>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                </FormItem>
            </Form>
        </Card>
    </div>
</template>
<script>
    import $http from '../../utils/axiosWrap'
    import Cookies from 'js-cookie';

    export default {
        data () {
            return {
                formValidate: {
                    serviceChargeRate: '',
                    usdId:'',
                    usdiatm:'',
                    usdtatm:'',
                    usdtfee:'',
                    serviceChargeRateKs: '',
                    ksId:'',
                    lowest: '',
                    highest: '',
                    aitcRelease: '',
                    oreRelease: '',
                    oreReleaseRatio: '',
                    aitcReleaseRatio: '',
//                    oreStatus: '',
                    canWithdrawRatio:'',
                    feeCtc: '',
                    buyLowest: '',
//                    buyHighest: '',
                    fee: '',
                    aitBuyLowest: '',
                    aitcBuyHighest: '',
                    creatime:'',
                    endtime:'',
                    returnOreTransfer:'',
                    highestNumber:'',
                    onOffs:'',
                    ctcExchangeRate:''
                },
                ruleValidate: {
                    serviceChargeRate: [
                        { required: true, message: 'USDI提现手续费不得为空', trigger: 'blur' }
                    ],
                    serviceChargeRateKs: [
                        { required: true, message: '矿石转账手续费不得为空', trigger: 'blur' }
                    ],
                    usdiatm: [
                        { required: true, message: 'USDI最低转账不得为空', trigger: 'blur' }
                    ],
                    usdtatm: [
                        { required: true, message: 'USDT最低转账不得为空', trigger: 'blur' }
                    ],
                    lowest: [
                        { required: true, message: '最低转账不得为空', trigger: 'blur' }
                    ],
                    highest: [
                        { required: true, message: '最高转账不得为空', trigger: 'blur' }
                    ],
                    aitcRelease: [
                        { required: true,  message: 'aitc释放周期(日)不得为空', trigger: 'blur' }
                    ],
                    aitcReleaseRatio: [
                        { required: true, message: 'aitc释放比例不得为空', trigger: 'blur' }
                    ],
                    oreRelease: [
                        { required: true,  message: '矿石本金释放周期(日)不得为空', trigger: 'blur' }
                    ],
                    oreReleaseRatio: [
                        { required: true, message: '矿石本金释放比例不得为空', trigger: 'blur' }
                    ],
//                    oreStatus: [
//                        { required: true,  message: '请选择是否开启矿机', trigger: 'blur' }
//                    ],
                    feeCtc: [
                        { required: true, message: 'CTC交易手续费不得为空', trigger: 'blur' }
                    ],
                    buyLowest: [
                        { required: true, message: 'CTC最低交易不得为空', trigger: 'blur' }
                    ],
//                    buyHighest: [
//                        { required: true, message: 'CTC最高交易不得为空', trigger: 'blur' }
//                    ],
                    fee: [
                        { required: true, message: 'BB交易手续费不得为空', trigger: 'blur' }
                    ],
                    aitBuyLowest: [
                        { required: true, message: 'BB最低交易不得为空', trigger: 'blur' }
                    ],
                    aitcBuyHighest: [
                        { required: true, message: 'BB最高交易不得为空', trigger: 'blur' }
                    ],
                    creatime: [
                        { required: true, message: '开始时间不得为空', trigger: 'blur' }
                    ],
                    endtime: [
                        { required: true, message: '结束时间不得为空', trigger: 'blur' }
                    ],
                    returnOreTransfer: [
                        { required: true, message: '奖励(锁仓)转账开始时间不得为空', trigger: 'blur' }
                    ],
                    highestNumber: [
                        { required: true, message: 'CTC挂单最高数量不得为空', trigger: 'blur' }
                    ],
                    ctcExchangeRate: [
                        { required: true, message: 'CTC兑换矿石汇率不得为空', trigger: 'blur' }
                    ],
                    canWithdrawRatio: [
                        { required: true, message: '网体可提现比例不得为空', trigger: 'blur' }
                    ],
                    onOffs:[
                        { required: true, message: '请选择网体提现状态', trigger: 'blur' }
                    ]
                },
                Message: ''
            }
        },
        created(){
            this.load()
        },
        methods: {
            setTime(time){
                var date = new Date(time);
                var month = date.getMonth() + 1
                var day =  date.getDate()
                var hours =   date.getHours()
                var minutes = date.getMinutes()
                var datese = date.getSeconds()
                if(datese /1  < 10){
                    datese = '0' +  datese
                }
                if(month /1  < 10){
                    month = '0' +  month
                }
                if(day /1  < 10){
                    day = '0' +  day
                }
                if(hours /1  < 10){
                    hours = '0' +  hours
                }
                if(minutes /1  < 10){
                    minutes = '0' +  minutes
                }
                return date.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + datese
            },
            handleSubmit (name) {
                let _this = this
                _this.formValidate.creatime += ''
                _this.formValidate.endtime += ''
                _this.formValidate.returnOreTransfer += ''
                _this.formValidate.canWithdrawRatio += ''
                _this.formValidate.onOffs += ''

                console.log(_this.formValidate.returnOreTransfer)

                _this.$refs[name].validate((valid) => {
                    if (valid) {
                        let params = new URLSearchParams()
                        params.append('feeSer',_this.formValidate.serviceChargeRate)
                        params.append('id','1')
                        params.append('currency','usd')
                        params.append('otherCurrency','usd')
                        params.append('lowest',_this.formValidate.lowest)
                        params.append('highest',_this.formValidate.highest)
                        params.append('aitcRelease',_this.formValidate.aitcRelease)
                        params.append('oreRelease',_this.formValidate.oreRelease)
                        params.append('oreReleaseRatio',_this.formValidate.oreReleaseRatio)
                        params.append('aitcReleaseRatio',_this.formValidate.aitcReleaseRatio)
                        params.append('oreStatus','0')
                        params.append('feeCtc',_this.formValidate.feeCtc)
                        params.append('aitBuyLowest',_this.formValidate.aitBuyLowest)
                        params.append('aitcBuyHighest',_this.formValidate.aitcBuyHighest)
                        params.append('aitcSelloutLowest',_this.formValidate.aitBuyLowest)
                        params.append('aitcSelloutHghest',_this.formValidate.aitcBuyHighest)
                        params.append('fee',_this.formValidate.fee)
                        params.append('buyLowest',_this.formValidate.buyLowest)
                        params.append('canWithdrawRatio',_this.formValidate.canWithdrawRatio)
                        params.append('buyLowest',_this.formValidate.buyLowest)
                        params.append('selloutHighest',_this.formValidate.buyHighest)
                        params.append('sysEnglishName',Cookies.get('user'))
                        params.append('creatime',_this.setTime(_this.formValidate.creatime))
                        params.append('endtime',_this.setTime(_this.formValidate.endtime))
                        params.append('returnOreTransfer',_this.setTime(_this.formValidate.returnOreTransfer))
                        params.append('ctcExchangeRate',_this.formValidate.ctcExchangeRate)
                        params.append('highestNumber',_this.formValidate.highestNumber)
                        params.append('onOff',_this.formValidate.onOffs)
                        $http.post('/sys/updateSys',params).then(function (res) {
                            if(res.suc){
                                let params = new URLSearchParams()
                                params.append('id','2')
                                params.append('currency','ore')
                                params.append('otherCurrency','ore')
                                params.append('feeSer',_this.formValidate.serviceChargeRateKs)
                                params.append('sysEnglishName',Cookies.get('user'))
                                $http.post('ServiceCharge/updateServiceCharge',params).then(function (suc) {
                                    if(suc){
                                        let params = new URLSearchParams()
                                        params.append('usdiatm',_this.formValidate.usdiatm)
                                        params.append('usdtatm',_this.formValidate.usdtatm)
                                        $http.post('sys/updateusdatm',params).then(function (suc) {
                                            if(suc){
                                                _this.$Message.success('修改成功!')
                                                _this.load()
                                            }else{
                                                _this.$Message.error('修改失败!')
                                            }
                                        })
                                    }else{
                                        _this.$Message.error('修改失败!')
                                    }
                                })
                            }else{
                                if(res.msg == "请先登录"){
                                    _this.$Message.error('请重新登录！');
                                }else{
                                    _this.$Message.error(res.msg);
                                }
                            }
                        })
                    } else {
                        _this.$Message.error('修改有误')
                    }
                })
            },
            handleReset (name) {
                this.$refs[name].resetFields();
            },
            load () {
                let _this = this
                let params = new URLSearchParams()
                //查询手续费汇率
                $http.post('/ServiceCharge/findAllServiceCharge',params).then(function (res) {
                    _this.formValidate.serviceChargeRate = res[0].serviceChargeRate + ''
                    _this.formValidate.usdId = res[0].serviceChargeId + ''
                    _this.formValidate.serviceChargeRateKs = res[1].serviceChargeRate + ''
                    _this.formValidate.ksId = res[1].serviceChargeId + ''
                })
                //查询USDI/USDT最低转账
                $http.post('/sys/getusdatm',params).then(function (res) {
                    _this.formValidate.usdiatm = res.result.usdiatm + ''
                    _this.formValidate.usdtatm = res.result.usdtatm + ''
                })
                //查询转账最低最高
                $http.post('/sys/getSysLimit',params).then(function (res) {
//                    _this.Message =
                    _this.formValidate.canWithdrawRatio = res.result[0].canWithdrawRatio + ''
                     if(res.result[0].switchOnoff == '1'){
                         _this.formValidate.onOffs = '1'
                     }else{
                         _this.formValidate.onOffs = '0'
                     }
                    _this.formValidate.lowest = res.result[0].transferLowest + ''
                    _this.formValidate.highest = res.result[0].transferHighest + ''
                    _this.formValidate.returnOreTransfer = res.result[0].returnOreTransfer + ''
                })
                //矿机限制
                $http.post('/sys/getSysCycle',params).then(function (res) {
                    _this.formValidate.aitcRelease = res.result[0].aitcLockRelease + ''
                    _this.formValidate.aitcReleaseRatio = res.result[0].aitcReleaseRatio + ''
                    _this.formValidate.oreRelease = res.result[0].orePrincipalRelease + ''
                    _this.formValidate.oreReleaseRatio = res.result[0].orePrincipalReleaseRatio + ''
//                    _this.formValidate.oreStatus = res.result[0].oreStatus + ''
                })
                //查询CTC
                $http.post('/sys/getgetSysCtcSetUp',params).then(function (res) {
                    _this.formValidate.feeCtc = res.result[0].ctcSelloutFeeSetting + ''
                    _this.formValidate.buyLowest = res.result[0].ctcSelloutLowest + ''
                    _this.formValidate.buyHighest = res.result[0].ctcSelloutHighest + ''
                    _this.formValidate.highestNumber = res.result[0].ctcHighestNumber + ''
                    _this.formValidate.ctcExchangeRate = res.result[0].ctcExchangeRate + ''

                })
                //查询BBC
                $http.post('/sys/getSysBbcSetUp',params).then(function (res) {
                    _this.formValidate.fee = res.result[0].feeSetting + ''
                    _this.formValidate.aitBuyLowest = res.result[0].bbcAitcBuyLowest + ''
                    _this.formValidate.aitcBuyHighest = res.result[0].bbcAitcBuyHighest + ''
                    _this.formValidate.creatime = res.result[0].bbcSysCreateTime + ''
                    _this.formValidate.endtime = res.result[0].bbcSysEndTime + ''
                })
            }
        }
    };
</script>
<style>

</style>
